import xadmin

from .models import Course, Lesson, Video, CourseResource
from apps.operation.models import UserAsk


class CourseAdmin(object):
    list_display = ['id', 'name', 'desc', 'course_org', 'teacher', 'learn_times', 'degree', 'students', 'detail']  # 后台管理显示具体列
    search_fields = ['name', 'desc', 'course_org', 'degree', 'students', 'detail']  # 配置搜索字段
    list_filter = ['name', 'desc', 'learn_times', 'course_org', 'degree', 'students', 'detail', 'teacher__name']  # 配置过滤字段
    list_editable = ['degree', 'desc']  # 在列表页可以快速直接编辑的字段


class LessonAdmin(object):
    list_display = ['id', 'name', 'course', 'add_time']  # 后台管理显示具体列
    search_fields = ['name', 'course']  # 配置搜索字段
    list_filter = ['name', 'course__name']  # 配置过滤字段,当过滤字段是外键时需要 ‘__’ 链接
    list_editable = ['name']  # 在列表页可以快速直接编辑的字段


class VideoAdmin(object):
    list_display = ['id', 'name', 'lesson', 'add_time']  # 后台管理显示具体列
    search_fields = ['name', 'lesson']  # 配置搜索字段
    list_filter = ['name', 'lesson', 'add_time']  # 配置过滤字段


class CourseResourceAdmin(object):
    list_display = ['id', 'name', 'course', 'add_time', 'file']  # 后台管理显示具体列
    search_fields = ['name', 'course', 'file']  # 配置搜索字段
    list_filter = ['name', 'course', 'add_time', 'file']  # 配置过滤字段


xadmin.site.register(Course, CourseAdmin)
xadmin.site.register(Lesson, LessonAdmin)
xadmin.site.register(Video, VideoAdmin)
xadmin.site.register(CourseResource, CourseResourceAdmin)


# 站点的全局配置
class BaseSetting(object):
    enable_themes = True  # 开启主题切换功能
    use_bootswatch = True  # 支持切换主题


xadmin.site.register(xadmin.views.BaseAdminView, BaseSetting)


class GlobalSettings(object):
    """xadmin的全局配置"""
    site_title = "慕学网管理后台"  # 设置站点标题
    site_footer = "慕学在线网"  # 设置站点的页脚
    menu_style = "accordion"  # 设置菜单折叠，在左侧，默认的
    # 设置models的全局图标, 列表参数 为表名
    global_search_models = [Course, Lesson, UserAsk]
    global_models_icon = {
        Course: "glyphicon glyphicon-tag", Lesson: "fa fa-cloud", UserAsk: "fa fa-envelope-o"
    }


xadmin.site.register(xadmin.views.CommAdminView, GlobalSettings)
